package itypes

import (
	"github.com/hwcer/updater"
	"github.com/hwcer/updater/operator"
	"server/share/config"
)

// 兼容老板概率组
var ItemsBong = &itemsGroupBong{IType: IType{id: config.ITypeItemGroupBong}}

type itemsGroupBong struct {
	IType
}

// Listener 独立概率
func (this *itemsGroupBong) Listener(u *updater.Updater, op *operator.Operator) {
	if op.Type != operator.TypesAdd || op.Value <= 0 {
		return
	}
	op.Type = operator.TypesResolve
	r := map[int32]int32{}
	this.Parse(u, r, op.IID, int32(op.Value))
	for k, v := range r {
		u.Add(k, v)
	}
}

func (this *itemsGroupBong) Parse(u *updater.Updater, r map[int32]int32, iid, num int32) {
	w := config.GetItemRandom()
	v := w.Bong[iid]
	if v == nil {
		return
	}
	for ; num > 0; num-- {
		for _, id := range v.Roll() {
			if id <= 0 {
				continue
			}
			c := config.Data.ItemGroupBong[id]
			if c != nil && c.Key > 0 && c.Num > 0 {
				r[c.Key] += c.Num
			}
		}
	}
}
